package cn.vcjf.washcar.api.service.controller;


import cn.vcjf.washcar.api.service.entity.MerchQrcode;
import cn.vcjf.washcar.api.service.service.MerchQrcodeService;
import cn.vcjf.washcar.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-07-20
 */
@Controller
@RequestMapping("/service/merchQrcode")
public class MerchQrcodeController {
     @Resource
     private MerchQrcodeService  merchQrcodeService;

     @RequestMapping("/addMerchQrcode")
     @ResponseBody
     public TableResult addMerchQrcode(MerchQrcode merchQrcode){
         merchQrcode.preInsert();
         boolean b = merchQrcodeService.insert(merchQrcode);
         return TableResult.Result(b);
     }

     @RequestMapping("/updateMerchQrcode")
     @ResponseBody
     public TableResult updateMerchQrcode(MerchQrcode merchQrcode){
         merchQrcode.preUpdate();
        boolean b = merchQrcodeService.updateById(merchQrcode);
         return TableResult.Result(b);
     }

     @RequestMapping("/findMerchQrcodeOne")
     @ResponseBody
     public TableResult findMerchQrcodeOne(MerchQrcode merchQrcode){

        EntityWrapper<MerchQrcode> wrapper = new EntityWrapper<MerchQrcode>();

        if(merchQrcode.getId()!=null){
            wrapper.eq("id",merchQrcode.getId());
        }
        //Todo

        MerchQrcode result = merchQrcodeService.selectOne(wrapper);

		return TableResult.Result(result);
     }

     @RequestMapping("/findMerchQrcodeList")
     @ResponseBody
     public TableResult findMerchQrcodeList(MerchQrcode merchQrcode){

        EntityWrapper<MerchQrcode> wrapper = new EntityWrapper<MerchQrcode>();

		if(merchQrcode.getId()!=null){
            wrapper.eq("id",merchQrcode.getId());
        }
        //Todo

        Page<MerchQrcode> page = new Page<MerchQrcode>(merchQrcode.getPage(), merchQrcode.getLimit());

        Page<MerchQrcode> result = merchQrcodeService.selectPage(page,wrapper);

		return TableResult.Result(result);

     }

     @RequestMapping("/deleteMerchQrcode")
     @ResponseBody
     public TableResult deleteMerchQrcode(MerchQrcode merchQrcode){
        merchQrcode.preUpdate();
        boolean b = merchQrcodeService.deleteById(merchQrcode.getId());
        return TableResult.Result(b);
     }

}
